package v3.chapter2.synStaticMethod; 

public class Run {

	public static void main(String[] args) {
		ThreadA a=new ThreadA();
		a.setName("a");
		a.start();
		
		ThreadB b=new ThreadB();
		b.setName("b");
		b.start();
	}
}

class ThreadA extends Thread{
	public void run() {
		Service.printA();
	}
}

class ThreadB extends Thread{
	public void run() {
		Service.printB();
	}
}

class Service {
	synchronized public static void printA() {
		try {
			System.out.println( "线程名称：" + Thread.currentThread().getName()+" 在 " + System.currentTimeMillis()+"进入 printA" );
			Thread.sleep(2000);
			System.out.println( "线程名称：" + Thread.currentThread().getName()+" 在 " + System.currentTimeMillis()+"离开 printA" );
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	synchronized public static void printB() {
		try {
			System.out.println( "线程名称：" + Thread.currentThread().getName()+" 在 " + System.currentTimeMillis()+"进入 printB" );
			Thread.sleep(2000);
			System.out.println( "线程名称：" + Thread.currentThread().getName()+" 在 " + System.currentTimeMillis()+"离开 printB" );
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}